package com.zhx.ad.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 *describe: 
 *
 *@author zhanghaixuan
 *@date 2019/02/01
 **/
@Slf4j
@Component
public class PostRequestFilter extends ZuulFilter {
	@Override
	public String filterType() {
		return FilterConstants.POST_TYPE;
	}
	@Override
	public int filterOrder() {
		return FilterConstants.SEND_RESPONSE_FILTER_ORDER-1;
	}
	@Override
	public boolean shouldFilter() {
		return true;
	}
	@Override
	public Object run() throws ZuulException {
		RequestContext currentContext = RequestContext.getCurrentContext();
		Long startTime =(Long) currentContext.get("startTime");

		long endTime = System.currentTimeMillis();

		long time = endTime - startTime;
		HttpServletRequest request = currentContext.getRequest();


		String requestURI = request.getRequestURI();

		log.info("requestURI: " +requestURI + ",uri:"+time/100+"ms");

		return null;
	}
}
